$(function () {
    initApiTreeMenu();
});


function initApiTreeMenu() {
    $.ajax({
        url: "/dms/query",
        data: JSON.stringify({"expand":true}),
        method: "post",
        dataType: "json",
        contentType: 'application/json',
        success: function (data) {
            for(var i  = 0 ; i < data.length ; i++){
                data[i].text = data[i].name;
            }
            var options = {
                levels: 2,
                color : "#fff",
                backColor : "#333",
                onhoverColor : "#4b545f",
                selectedColor : "#fff",
                selectedBackColor : "#767d85",
                data: Tree.toTree({data:data,rootId:0,id:"treeId",parentId:"treeParentId",children : "children",sort:"sort"}),
                onNodeSelected : function (node,data) {
                    if(data.hasOwnProperty("children") && data.children && data.children.length > 0){ return ;  }
                    $("#apiMenuSelectedId").val(data.id);
                    $("#apiTable").bootstrapTreeTable("refresh",{"id":data.id});
                }
            };
            $('.api-menu').treeview(options);
        },
    });
}